﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Libs.HR;

public partial class Pages_Hr_Employees_List : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppUtils.CheckLogin();
        Title = Title + " - Danh sách nhân sự";
        if (!IsPostBack)
        {
            GetDropDownList();
            BindData();
        }
    }

    protected string ImgUrl(string id)
    {
        return Constant.ADMIN_PATH + Resources.Url.FileDataView + "?id=" + id;
    }

    private void GetDropDownList()
    {
        // Department
        var _Department = new Departments();
        drpDepartment.DataSource = _Department.GetTList();
        drpDepartment.DataBind();
        drpDepartment.Items.Insert(0, new ListItem("Chọn phòng ban:", "0"));

        // Loại hợp đồng
        var _ContractType = new ContractType();
        drpContractType.DataSource = _ContractType.GetTList();
        drpContractType.DataBind();
        drpContractType.Items.Insert(0, new ListItem("Chọn loại hợp đồng:", "0"));
    }

    private void BindData()
    {
        var _Employee = new Employees();
        int total = 0;
        int pageSize = Convert.ToInt32(drpPageSize.SelectedValue);
        int pageIndex = Convert.ToInt32(drpPage.SelectedValue);
        int departmentID = Convert.ToInt32(drpDepartment.SelectedValue);
        int contractTypeID = Convert.ToInt32(drpContractType.SelectedValue);
        rptList.DataSource = _Employee.GetTList(departmentID, contractTypeID, pageIndex, pageSize, ref total);
        rptList.DataBind();

        lblTotal.Text = "(" + total.ToString() + ")";
        total = (total - 1) / pageSize + 1;
        if (total == 0) total = 1;
        drpPage.Items.Clear();
        for (int i = 1; i <= total; i++)
        {
            drpPage.Items.Add(new ListItem(i.ToString()));
        }

        try
        {
            drpPage.SelectedValue = pageIndex.ToString();
        }
        catch
        {
        }
    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.EmployeesAdd);
    }

    protected void btPage_Click(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btView_Click(object sender, EventArgs e)
    {
        BindData();
    }
}

